import {reactive, ref, Ref} from "vue";
import axios from '@/utils/axios';
import {message} from "ant-design-vue";

class CompactionInfo{
    deviceId:number|null = null
    wheelWidth:number|null = null
    wheelJoint:number|null = null
}

// 振动碾
export default ()=>{
    const compactionViewInfo = ref({
        showModal: false
    })

    const compactionInfo = <Ref<CompactionInfo>>ref({
        deviceId: null,
        wheelWidth: null,
        wheelJoint: null
    })

    // 查找详细信息
    const getCompactionInfo = (deviceId:number,callback:Function|null = null)=>{
        compactionInfo.value = new CompactionInfo()
        axios.post("/comp/findDeviceParameterByDeviceId",{deviceId:deviceId}).then((res:any)=>{
            if(res.success){
                Object.assign(compactionInfo.value,res.data)
            }else{
                compactionInfo.value.deviceId = deviceId
            }
            if(callback) callback()
        })
    }

    // 增加||更新详细信息
    const setCompactionInfo = (callback:Function|null = null)=>{
        axios.post("/comp/saveDeviceParameterByDeviceId",compactionInfo.value).then((res:any)=>{
            if(res.success){
                message.info("保存成功")
                if(callback) callback()
            }else{
                message.info(res.msg)
            }
        })
    }

    return {
        compactionViewInfo,
        compactionInfo,
        getCompactionInfo,
        setCompactionInfo
    }
}